-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WCA Live Result Admin #1: Submit and Updating Results #10776
Conversation
app/controllers/live_controller.rb
Outdated
new_attempts = results.map.with_index(1) do |r, i| | ||
same_result = previous_attempts.find_by(result: r, attempt_number: i) | ||
if same_result.present? | ||
same_result | ||
else | ||
different_result = previous_attempts.find_by(attempt_number: i) | ||
new_result = LiveAttempt.build(result: r, attempt_number: i) | ||
different_result&.update(replaced_by_id: new_result.id) | ||
new_result | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: I have a hunch there might be an even more efficient way to handle this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will play around later when I have more headspace.
useEffect(() => { | ||
if (results) { | ||
setAttempts(results[currentIndex].attempts.map((a) => a.result)); | ||
} | ||
}, [currentIndex, results]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the query ever re-fetched? i.e. Does results
ever change? If not, then you indeed do need a side effect to set attempts
when the data first loads, but you could explicitly update attempts
when the "<" or ">" button is clicked instead of it being a side effect of the index changing. That would minimize the use of effects (even though it's the same number of useEffects
, that effect would only be happening once).
Simple Submitting/Updating Results and double checking them. Does not include calculating advancing/rankings/records. Those will be follow up PRs (which I have already done, but I want to add tests).
Have not checked if I deleted everything related to those features, will do after dinner.